using System;
using System.Collections.Generic;
using System.Text;
using Ghasam.Business.Domain.Entity;
using NHibernate.Expression;
using NHibernate;

namespace Ghasam.Business.DAO.Impl
{
    public class SalesPersonDao : DaoBase<SalesPerson>, ISalesPersonDao
    {
        public IList<SalesPerson> SortSalesPerson(string param, bool asc)
        {
            Order dir = new Order(param, asc);
            ICriteria crit = base.Session.CreateCriteria(typeof(SalesPerson));
            crit.AddOrder(dir);
            return crit.List<SalesPerson>();
        }

        public IList<SalesPerson> FindByTitleLike(string title) {
            ICriteria crit = base.Session.CreateCriteria(typeof(SalesPerson));
            crit.Add(Expression.Like("Title", title, MatchMode.Start));
            return crit.List<SalesPerson>();
        }

        public SalesPerson FindByTitle(string title) {
            ICriteria crit = base.Session.CreateCriteria(typeof(SalesPerson));
            crit.Add(Expression.Like("Title", title, MatchMode.Exact));
            return crit.UniqueResult<SalesPerson>();
        }
    }
}
